/**
 * 公共查询
 * 支持：组织机构、设备号、组织机构+设备号
 */

/**
* 查询带设备的组织机构树形结构
 * @return
 */

function selOrgStrapVcl(obj){
	var searchtext = $(".searchtext").eq(0);
	var searchdiv = $(".orgstrapvcl");
	if(searchdiv.length>0){
		if(searchdiv.is(":visible")){
			orgstrapvclScrollTop = $(".orgstrapvcl").scrollTop();
			searchdiv.hide();
		}else{
			searchdiv.show();
			searchdiv.scrollTop(orgstrapvclScrollTop);
		}
	}else{
		var searchtextleft =  searchtext.offset().left;
		var searchtexttop = searchtext.offset().top+searchtext.height()+2;
		var searchtextwidth = searchtext.width()+$(".searchbtn").width()+1;
		var selDiv = $("<div>",{'id':'orgstrapvcl'});
		selDiv.html("<center><img src='images/loading.gif' /><br/>正在加载请稍后......</center> ")
		.addClass("orgstrapvcl")
		.css("left",searchtextleft)
		.css("top",searchtexttop)
		.css("width",searchtextwidth)
		.appendTo($("body"));
		if(obj.id=='NewMsg'){
		$.ajax({
			url:'selbase!selOrgStrapVcl.action',
			data:{'frameType':3},
			dataType:'text',
			type:'post',
			error:function(){},
			success:function(data){
				selDiv.html(data)
				$(".orgstrapvcl").click(function(event){event.stopPropagation();});
			}
		});
	}else{
		$.ajax({
			url:'selbase!selOrgStrapVcl.action',
			data:{'frameType':1},
			dataType:'text',
			type:'post',
			error:function(){},
			success:function(data){
				selDiv.css("display","none")
						.html(data);
				if($("#orgCode0").val().length==0){
					$('input[name="orgCodeBack"]').each(function(){
						if($(this).attr("checked")=="checked"){
							$(this).removeAttr("checked");
						}
					}); 
				}
				selDiv.css("display","block");
				$(".orgstrapvcl").click(function(event){event.stopPropagation();});
			}
		});
	}
	}
}

/**
* 查询组织机构树形结构
 * @return
 */
function selOrg(e){
	var searchdiv = $("#orgnostrapvcl");
	if(searchdiv.length>0){
		if(searchdiv.is(":visible")){
			searchdiv.hide();
		}else{
			searchdiv.show();
		}
		return ;
	}else{
		var selOrg$ = $(".selOrg").eq(0);
		var searchtextleft =  selOrg$.offset().left;
		var searchtexttop = selOrg$.offset().top+selOrg$.height()+2;
		$.ajax({
			url:'selbase!selOrgStrapVcl.action',
			data:{'frameType':2},
			dataType:'text',
			type:'post',
			error:function(){},
			success:function(data){
				var selDiv = $("<div>",{'id':'orgnostrapvcl'});
				selDiv.html(data)
				.addClass("orgstrapvcl")
				.css("left",searchtextleft)
				.css("top",searchtexttop)
				.css("float","none")
				.appendTo($("body"));
				$(".orgstrapvcl").click(function(event){event.stopPropagation();});
			}
		});
	}
}
function exportVehicleNumber(vclNum,obj){
	var value="";
	if($(obj).attr("checked")=="checked"){
		/*$(obj).attr("checked","checked");*/
		if($(".searchtext").eq(0).val().length == 0 || $(".searchtext").eq(0).val() == '请输入设备号/发动机号/底盘号'){
			value = vclNum;
		}else{
			var str = $(".searchtext").eq(0).val();
			value = str + "," +vclNum;
		}
	}else{
		/*$(obj).removeAttr("checked");*/
		$.each( $(".searchtext").eq(0).val().split(","), function(i, n){
			if(n == vclNum ){
				$(this).remove();
			}else{
				if(value.length != 0){
					value = value + ",";
				}
				value = value + n;
			}
		});
	}
	$(".searchtext").eq(0).val(value);
	orgstrapvclScrollTop = $(".orgstrapvcl").scrollTop();
//	$(".orgstrapvcl").hide();
}
/*************/
//在库终端
function zd_open(cat,img_lx){
	if(cat.style.display=="none"){
		cat.style.display="inline";
		document.getElementById(img_lx).src="./images/org/tminus.gif";
	}else{
		cat.style.display="none"; 
		document.getElementById(img_lx).src="./images/org/tplus.gif";
	}
}
//在库机械
function jx_open(cat,img_lx,com_num){
	if(cat.style.display=="none"){
		cat.style.display="inline";
		if(com_num>0){
			document.getElementById(img_lx).src="./images/org/tminus.gif";
		}else{
			document.getElementById(img_lx).src="./images/org/lminus.gif";
		}
		
	}else{
		cat.style.display="none"; 
		if(com_num>0){
			document.getElementById(img_lx).src="./images/org/tplus.gif";
		}else{
			document.getElementById(img_lx).src="./images/org/lplus.gif";
		}
		
	}
}

//最终用户的机械
function com_open(OrganizationCode,is_end){
	var cat = eval("company_down_"+OrganizationCode);
	if(cat.style.display=="none"){
		cat.style.display="inline";
		if(is_end=="yes"){
			document.getElementById("company_img_lx_"+OrganizationCode).src="./images/org/lminus.gif";
		}else{
			document.getElementById("company_img_lx_"+OrganizationCode).src="./images/org/tminus.gif";
		}
	}else{
		cat.style.display="none"; 
		if(is_end=="yes"){
			document.getElementById("company_img_lx_"+OrganizationCode).src="./images/org/lplus.gif";
		}else{
			document.getElementById("company_img_lx_"+OrganizationCode).src="./images/org/tplus.gif";
		}
	}
}

//定义AJac
var Req = Ajax();	//定义一个初始化的变量
function Ajax(){	//主要是用于初始化
	var httprequest = null;
	//mozilla,safari等浏览器的初始化方式(可以不写)
	if(window.XMLHttpRequest){	
		httprequest = new XMLHttpRequest();
		if(httprequest.overrideMimeType){
			httprequest.overrideMimeType('text/xml');
		}
	//ie浏览器的初始化方式
	}else if(window.ActiveXObject){	
		try{
			httprequest = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e){
			try{
				httprequest = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){}
		}
	}
	return httprequest;
}

//左侧组织结构--动态查询康明斯下级信息
function send(up_OrganizationID,up_OrganizationCode,up_OrganizationName,OrganizationTypeID,up_td_Str,is_end,frameType){
	var cat = eval("down_"+up_OrganizationCode);
	if(cat.style.display=="none"){
		document.getElementById("name_"+up_OrganizationCode).innerHTML = "正在加载...";
		if(is_end=="yes"){
			document.getElementById("img_lx_"+up_OrganizationCode).src="./images/org/lminus.gif";
		}else{
			document.getElementById("img_lx_"+up_OrganizationCode).src="./images/org/tminus.gif";
		}

		if(Req.readyState == 4 || Req.readyState == 0){
			Req.open("post","selbase!selDataDMI.action?up_OrganizationID="+up_OrganizationID+"&up_OrganizationCode="+up_OrganizationCode+"&OrganizationTypeID="+OrganizationTypeID+"&up_td_Str="+up_td_Str+"&is_end="+is_end+"&frameType="+frameType,true);
			Req.onreadystatechange = function(){
				if(Req.readyState == 4){
					var str = Req.responseText;
					document.getElementById("name_"+up_OrganizationCode).innerHTML = up_OrganizationName;
					if(str!=""){
						cat.style.display="block";
						document.getElementById("down_"+up_OrganizationCode).innerHTML = str;
					}else{
						cat.style.display="none";
						document.getElementById("img_wjb_"+up_OrganizationCode).src="./images/org/folder.gif";
					}
				}
			};
			Req.send(null);
		}
	}else{
		cat.style.display="none"; 
		if(is_end=="yes"){
			document.getElementById("img_lx_"+up_OrganizationCode).src="./images/org/lplus.gif";
		}else{
			document.getElementById("img_lx_"+up_OrganizationCode).src="./images/org/tplus.gif";
		}
	}
}
//带有复选框的组织机构设备树--动态查询康明斯下级信息
function sendCheckBox(up_OrganizationID,up_OrganizationCode,up_OrganizationName,OrganizationTypeID,up_td_Str,is_end,frameType){
	var cat = document.getElementById("down_"+up_OrganizationCode);
	var value = document.getElementById("img_lx_"+up_OrganizationCode).value;
	if(cat.style.display=="none"){
		if(is_end=="yes"){
			document.getElementById("img_lx_"+up_OrganizationCode).src="./images/org/lminus.gif";
		}else{
			document.getElementById("img_lx_"+up_OrganizationCode).src="./images/org/tminus.gif";
		}
		if(value==0){
			document.getElementById("name_"+up_OrganizationCode).innerHTML = "正在加载...";
			var isSelected = document.getElementById("orgCode_"+up_OrganizationCode).checked;
			if(Req.readyState == 4 || Req.readyState == 0){
				Req.open("post","selbase!selDataDMICheckBox.action?up_OrganizationID="+up_OrganizationID+"&up_OrganizationCode="+up_OrganizationCode+"&OrganizationTypeID="+OrganizationTypeID+"&up_td_Str="+up_td_Str+"&is_end="+is_end+"&frameType="+frameType+"&isSelected="+isSelected,true);
				Req.onreadystatechange = function(){
					if(Req.readyState == 4){
						var str = Req.responseText;
						document.getElementById("name_"+up_OrganizationCode).innerHTML = up_OrganizationName;
						if(str!=""){
							cat.style.display="block";
							document.getElementById("down_"+up_OrganizationCode).innerHTML = str;
							document.getElementById("img_lx_"+up_OrganizationCode).value = "1";
						}else{
							cat.style.display="none";
//							document.getElementById("img_wjb_"+up_OrganizationCode).src="./images/org/folder.gif";
						}
					}
				};
				Req.send(null);
			}
		}else{
			document.getElementById("name_"+up_OrganizationCode).innerHTML = up_OrganizationName;
			cat.style.display="block";
		}
	}else{
		cat.style.display="none"; 
		if(is_end=="yes"){
			document.getElementById("img_lx_"+up_OrganizationCode).src="./images/org/lplus.gif";
		}else{
			document.getElementById("img_lx_"+up_OrganizationCode).src="./images/org/tplus.gif";
		}
	}
}

/**
 * 带有复选框的组织机构设备树--获取所选组织机构Code的集合
 * @return
 */
function getCheckedDBCodes(){
	var SMSDB="";
	var len = $('input[id^="orgCode_"]:checked').length;
	if(len>0){
		$('input[id^="orgCode_"]:checked').each(function(){
			var codes = $(this).val();
			SMSDB+=codes+",";
			$("#DBVcl_DBCodes").val(SMSDB);
			var img_lx_ = document.getElementById("img_lx_"+codes);
			var value=-1;
			if(img_lx_!=null){
				value=img_lx_.value;
			}
			var isSelected = document.getElementById("orgCode_"+codes).checked;
			if(value==0 && isSelected){
				var url = "selbase!getCheckedDBCodes.action?up_OrganizationCode="+codes;
				$.ajax({
					url : url,
					dataType : "text", // 必须要指明，为了下面的循环
					cache : false,
					data:{},
					type:'post',
					success : function(data) {
						if(data.length>0){
							SMSDB += data;
							$("#DBVcl_DBCodes").val(SMSDB);
						}
					},
					complete : function() {
					},
					error : function() {
						
					}
				});
			}
		});
	}else{
		$("#DBVcl_DBCodes").val("");
	}
}
/**
 * 带有复选框的组织机构设备树--获取所选设备ID的集合
 * @return
 */
function getCheckedVclIDs(){
	var SMSVcl="";
	var len = $('input[id^="orgCode_"]:checked').length;
	if(len>0){
		$('input[id^="orgCode_"]:checked').each(function(){
			var codes = $(this).val();
			$('input[id="vclIDTree_'+codes+'"]:checked').each(function(){
				var id = $(this).val();
				SMSVcl+=id+",";
			});
			$("#DBVcl_VclIDs").val(SMSVcl);
			var img_lx_ = document.getElementById("img_lx_"+codes);
			var value=-1;
			if(img_lx_!=null){
				value=img_lx_.value;
			}
			var isSelected = document.getElementById("orgCode_"+codes).checked;
			if(value==0 && isSelected){
				var url = "selbase!getCheckedVclIDs.action?up_OrganizationCode="+codes;
				$.ajax({
					url : url,
					dataType : "text", // 必须要指明，为了下面的循环
					cache : false,
					data:{},
					type:'post',
					success : function(data) {
						if(data.length>0){
							SMSVcl += data;
							$("#DBVcl_VclIDs").val(SMSVcl);
						}
					},
					complete : function() {
					},
					error : function() {
						
					}
				});
			}
		});
	}else{
		$("#DBVcl_VclIDs").val("");
	}	
}
/**
 * 带有复选框的组织机构人员树--获取所选设备ID的集合
 * @return
 */
function getCheckedUserIDs(){
	var SMSUserID="";
	var SMSUserName = "";
	var len = $('input[id^="orgCode_"]:checked').length;
	if(len>0){
		$('input[id^="orgCode_"]:checked').each(function(){
			var codes = $(this).val();
			$('input[id="userIDTree_'+codes+'"]:checked').each(function(){
				var id = $(this).val().split(",");
				SMSUserID+=id[0]+",";
				SMSUserName += id[1]+",";
			});
			$("#DBVcl_UserIDs").val(SMSUserID);
			$("#DBVcl_UserNames").val(SMSUserName);
			var img_lx_ = document.getElementById("img_lx_"+codes);
			var value=-1;
			if(img_lx_!=null){
				value=img_lx_.value;
			}
			var isSelected = document.getElementById("orgCode_"+codes).checked;
			if(value==0 && isSelected){
				var url = "selbase!getCheckedUserIDs.action?up_OrganizationCode="+codes;
				$.ajax({
					url : url,
					dataType : "text", // 必须要指明，为了下面的循环
					cache : false,
					data:{},
					type:'post',
					success : function(data) {
						if(data.length>0){
							var dd = data.split("@@@");
							SMSUserID += dd[0];
							SMSUserName += dd[1];
							$("#DBVcl_UserIDs").val(SMSUserID);
							$("#DBVcl_UserNames").val(SMSUserName);
						}
					},
					complete : function() {
					},
					error : function() {
						
					}
				});
			}
		});
	}else{
		$("#DBVcl_UserIDs").val("");
		$("#DBVcl_UserNames").val("");
	}	
}
function getCheckedVclID(obj){
	var vclid = $(obj).val();
	var DBVcl_VclIDs = $("#DBVcl_VclIDs").val();
	if(!!$(obj).attr("checked")){
		var isExist = DBVcl_VclIDs.indexOf(vclid+",");
		if(isExist<0){	//不存在
			DBVcl_VclIDs+=vclid+",";
		}
		$("#DBVcl_VclIDs").val(DBVcl_VclIDs);
	}else{	//删除ID
		$("#DBVcl_VclIDs").val(DBVcl_VclIDs.replace(vclid+",",""));
	}
}
function getCheckedUserID(obj){
	var vclid = $(obj).val().split(",");
	var DBVcl_UserIDs = $("#DBVcl_UserIDs").val();
	var DBVcl_UserNames = $("#DBVcl_UserNames").val();
	if(!!$(obj).attr("checked")){
		var isExist = DBVcl_UserIDs.indexOf(vclid[0]+",");
		if(isExist<0){	//不存在
			DBVcl_UserIDs+=vclid[0]+",";
		}
		$("#DBVcl_UserIDs").val(DBVcl_UserIDs);
		
		var isExist_Name = DBVcl_UserNames.indexOf(vclid[1]+",");
		if(isExist_Name<0){	//不存在
			DBVcl_UserNames+=vclid[1]+",";
		}
		$("#DBVcl_UserNames").val(DBVcl_UserNames);
	}else{	//删除ID
		$("#DBVcl_UserIDs").val(DBVcl_UserIDs.replace(vclid[0]+",",""));
		$("#DBVcl_UserNames").val(DBVcl_UserNames.replace(vclid[1]+",",""));
	}
}
/**
 * 页面加载完执行
 */
//选中的设备号输入框
var searchtextObj;
var searchtouchObj;
var orgstrapvclScrollTop;
$(function(){
	//缓存
	var cache = {};
	//设备号输入提示（高级查询按钮前Input）
	var searchtext = $(".searchtext");
	var searchbtn = $(".searchbtn");
	//设备号输入提示
	var searchvcl = $(".searchvcl");
	//设备号输入提示
	var searchvcltype = $(".searchvcltype");
	var searchFltCode = $(".searchFltCode");				//jinjiayu20140605增加故障代码输入提示
	var searchCity = $(".searchCity");                      //jinjiayu20140923增加城市名输入提示
	//提示框属性
	var searchtextleft;
	var searchtexttop;
	var searchtextwidth;
	var searchtextheight;
	//显示提示框，obj：触发操作的目前目标对象；type：操作类型（1：设备号+发动机   2：设备号  3：设备型号）
	var isAjax = true;
	var displayTip = function(obj,type,url){
		$(obj).keyup(function(e){
			//显示框
			var searchsel = $("#searchsel");
			//设置属性
			searchtextleft =  $(obj).offset().left;
			searchtexttop = $(obj).offset().top+$(obj).height()+2;
			if(type==1){
				searchtextwidth = $(obj).width()+searchbtn.width()+2;
			}else{
				searchtextwidth = $(obj).width()+2;
			}
			var offset = 15;
			//设置提示框对象
			searchtextObj = $(obj);
			//过滤操作
			if(e.keyCode==13)return ;
			var searchVcl = $(obj).val();
			if(searchVcl==''){
				searchsel.remove();
				return ;
			}
			//清除提示框
			if(searchsel.length>0)searchsel.remove();
			if(checkPrompt())return ;
			
			var callBack = function(data){
				eval('var list = '+data);
				var objs = list.data;
				if(objs.length==0){
					return ;
				}else{
					var select$ = $("<select>")
					.attr("id","searchsel")
					.css("position","absolute")
					.css("left",searchtextleft)
					.css("top",searchtexttop)
					.css("width",searchtextwidth)
					.addClass("searchsel"+type);
					var counts = 0;
					if((navigator.userAgent.match(/iPad/i))){
						select$.get(0).options.add(new Option('',''));
					}
					$.each(objs,function(i,obj){
						counts++;
						var option;
						if(type==1){
							
							option = new Option(obj.vehiclenumber+" / "+obj.esnnumber+" / "+obj.chassisnumber,obj.vehiclenumber);
						}else if(type==2){
							option = new Option(obj.vehiclenumber,obj.vehiclenumber);
						}else if(type==3){
							option = new Option(obj.vehicletypename,obj.vehicletypename);
						}else if(type==4){
							option = new Option(obj.sysism_code,obj.sysism_code);
						}else{
							option = new Option(obj.name,obj.name);
						}
						select$.get(0).options.add(option);
					});
					searchtextheight=30*counts-offset*(counts-1);
					select$.get(0).options[0].selected = "selected";
					//进行非iPad单独设置
					if(!(navigator.userAgent.match(/iPad/i))){
						select$.attr("multiple","multiple");
						//提示框高度设定 jinjiayu20140605
						if(searchtextheight>400){
							searchtextheight=400;
						}
						select$.height(searchtextheight);
					}
					select$.appendTo($("body"));
					//进行iPad单独设置
					if((navigator.userAgent.match(/iPad/i))){
						select$.click(function(event){event.stopPropagation();});
						select$.change(function(){
							$(obj).val(select$.val());
							select$.remove();
						});
					}else{
						bindSelClick();
						enterClick();
					}
				}
			};
			
			if ( searchVcl+"type"+type in cache ) {
				callBack(cache[searchVcl+"type"+type]);
				return ;
			}
			if(isAjax){
				isAjax = false;
				$.ajax({
					url:url,
					data:{'searchVal':searchVcl,'type':type},
					dataType:'text',
					type:'post',
					success:function(data){
						cache[searchVcl+"type"+type] = data;
						callBack(data);
						isAjax = true;
					}
				});
			}
		});
	};
	
	//加载设备号输入提示（高级查询按钮前Input）
	if(searchtext!=undefined&&searchtext.length>0){
		searchtext.each(function(){
			displayTip($(this),1,'selbase!getAccount_VehicleNumber.action');
		});
		//点击放大镜按钮
		searchbtn.click(function(e){
			
			selOrgStrapVcl(this);
			e.stopPropagation();
			//释放设备提示框
			$("#searchsel").remove();
		});
		//点击高级查询按钮前Input
		searchtext.click(function(event){
			event.stopPropagation();
			if($(".orgstrapvcl").is(":visible")){
				orgstrapvclScrollTop = $(".orgstrapvcl").scrollTop();
				$(".orgstrapvcl").hide();
			}
		});
		//光标定位高级查询按钮前Input
		searchtext.focus(function(event){
			if($(this).val().replace(/(^\s*)|(\s*$)/g, "")=='请输入设备号/发动机号/底盘号')$(this).val('');
		});
	}
	//加载设备号输入提示
	if(searchvcl!=undefined&&searchvcl.length>0){
		displayTip($(searchvcl),2,'selbase!getAccount_VehicleNumber.action');
	}
	//jinjiayu20140605加载故障代码输入提示searchFltCode
	if(searchFltCode!=undefined&&searchFltCode.length>0){
		searchFltCode.click(function(event){
			event.stopPropagation();
		});
		displayTip($(searchFltCode),4,'selbase!getSearchFltCode.action');
	}
	//jinjiayu20140923加载城市名输入提示searchCity
	if(searchCity!=undefined&&searchCity.length>0){
		searchCity.click(function(event){
			event.stopPropagation();
		});
		displayTip($(searchCity),5,'selbase!getSearchCity.action');
	}
	//加载设备型号输入提示
	if(searchvcltype!=undefined&&searchvcltype.length>0){
		searchvcltype.click(function(event){
			event.stopPropagation();
		});
		displayTip($(searchvcltype),3,'selbase!getVclTypePrompt.action');
	}
	//jinjiayu20140605加载故障代码输入提示searchFltCode
	if(searchFltCode!=undefined&&searchFltCode.length>0){
		searchFltCode.click(function(event){
			event.stopPropagation();
		});
		displayTip($(searchFltCode),4,'selbase!getSearchFltCode.action');
	}
	//页面滚动条滚动
	$(".bodyWidth").scroll(function(){
		if($(".orgstrapvcl").length>0){
			searchtextObj = $(".orgstrapvcl");
			if($('#orgnostrapvcl').length>0){
				searchtouchObj = $(".selOrg");
			}else if($('#orgstrapvcl').length>0){
				searchtouchObj = $(".searchtext");
			}
		}else if($("#searchsel").length>0){
			searchtextObj = $("#searchsel");
			if($(".searchsel1").length>0){
				searchtouchObj = $(".searchtext");
			}else if($(".searchsel2").length>0){
				searchtouchObj = $(".searchvcl");
			}else if($(".searchsel3").length>0){
				searchtouchObj = $(".searchvcltype");
			}
		}
		if(searchtextObj!=null&&searchtextObj!=undefined&&searchtouchObj!=null&&searchtouchObj!=undefined){
			searchtextleft =  searchtouchObj.offset().left;
			searchtexttop = searchtouchObj.offset().top+searchtouchObj.height();
			searchtextObj.css("left",searchtextleft);
			searchtextObj.css("top",searchtexttop+2);
		}
		if($("#nowOrgCode").length>0){
			searchtextObj = $("#nowOrgCode");
			searchtouchObj = $(".searchtext").eq(0);
			var width = searchtextObj.width();
			var searchtextleft =  searchtouchObj.offset().left-8;
			var searchtexttop = searchtouchObj.offset().top;
			searchtextObj.css("left",searchtextleft-width);
			searchtextObj.css("top",searchtexttop);
		}
	});
	//组织机构树形提示（不包含设备号）
	var selOrg$ = $(".selOrg").eq(0);
	if(selOrg$!=undefined&&selOrg.length>0){
		selOrg$.click(function(e){
			selOrg(e);
			e.stopPropagation();
		});
	}
	//点击页面
	$(document).click(function(event){
		if($("#searchsel").length>0)$("#searchsel").remove();
		if($(".orgstrapvcl").length>0){
			orgstrapvclScrollTop = $(".orgstrapvcl").scrollTop();
			$(".orgstrapvcl").hide();
		}
	});
	//初始化当前组织机构
	var nowOrgCode = $('input[name=orgCode]');
	/*if(nowOrgCode.length>0&&nowOrgCode.val()!=''){
		selOrgCode(nowOrgCode.val(),window.parent.nowOrgCode,'','no');
	}*/
	//selOrgCode(nowOrgCode.val(),window.parent.nowOrgCode,'','no');
	selOrgCode('','','','no');
	//判断高级查询项是否关闭
	if(!window.parent.selTermState){
		if($("li .search_content").length>0){
			$("li .search_content").slideUp("fast");
			$(".more").attr("src", "images/zh_CN/more.png");
			var divheight;
			var scheight;
			if($(".search_content").length>0){
				scheight = $(".search_content").height();
			}
			if($('.tbl_list').length>0){
				divheight = $('.tbl_list').height();
				$('.tbl_list').animate({height:divheight+scheight+20},"fast");
			}
		}
	}
});

function bindSelClick(){
	$("#searchsel").unbind("click");
	$("#searchsel").click(function(){
		selClick($(this));
	});
}

function selClick(obj){
	searchtextObj.focus();
	if($(obj).length<=0||obj==undefined)return ;
	var index = $(obj).get(0).selectedIndex;
	searchtextObj.val($(obj).get(0).options[index].value);
	$(obj).remove();
};

function checkPrompt(){
	if($("#searchsel").length>0||$(".orgstrapvcl").is(":visible"))return true;
}

function enterClick(){
	$(document).unbind("keydown");
	$(document).keydown(function(e){
		if(e.keyCode==13){
			if($("#searchsel").length==0)return ;
			selClick($("#searchsel"));
			return false;
		}else if(e.keyCode==38||e.keyCode==40){
			if($("#searchsel").length>0)$("#searchsel").focus();
		}
	});
}

function selOrgCode(orgCode,orgName,obj,qureyflag){
	var searchtext = $(".searchtext");
	if(searchtext.length<=0)return ;
	var content = "";
	var zoomContent = "";//名称
	var orgCodeContent = "";//code码
	$("input[name=orgCode]").val("");
	$("#nowOrgCode").remove();
	$('input[name="orgCodeBack"]').each(function(){
		if($(this).attr("checked")=="checked"){
			$(this).attr("checked","checked");
		if(content.length != 0){
			content = content + ",";
		}else{
			content = "当前机构：";
		}
		content = content + $(this).val();
		if(orgCodeContent.length != 0){
			orgCodeContent = orgCodeContent + ",";
		}
		orgCodeContent = orgCodeContent + $(this).attr("id");
		
		}else{
			$(this).removeAttr("checked");
			
		}
		
	}); 
	if(qureyflag!="no"){
		$("#orgCode0").val(orgCodeContent);
	}
	
	if(content.length > 25){
		zoomContent = content.substring(0, 25)+"...";
	}else{
		zoomContent = content;
	}
	if(qureyflag=="no"){
	if($("#orgCode0").length>0){
	if($("#orgCode0").val().length>0){
		$.ajax({
			url:'selbase!selOrgStrapVcltwo.action',
			data:{"type":"1"},
			dataType:'text',
			type:'post',
			error:function(){		
			},
			success:function(data){
				var div$ = $("<div>").attr("id","nowOrgCode")
				 .attr("title",content)
	  			 .css("position","absolute")
	  			 .html(data);
				if(data==""){
					div$.css("display","none");
				}
				
				var img$ = $("<img>").attr("id","closeImg")
							.attr("src","images/custom/close.gif")
							.attr("title","关闭");
				var input$ = $("<input>").attr("id","inputImg")
				.css("display","none")
				.val(data);
				input$.appendTo(div$)
				img$.appendTo(div$);
				div$.appendTo($("body"));
				var width = div$.width();
				var searchtextleft =  searchtext.offset().left-18;
				var searchtexttop = searchtext.offset().top;
				var left = searchtextleft-width;
				var top = searchtexttop;
				div$.css("left",left)
				.css("top",top)
				.css("display","block")
				.css("width",width+10)
				.addClass("orgCode");
				img$.click(function(){
					$("#orgCode0").val("");
					$("#zoomContent0").val("");
					if($("#orgstrapvcl").length>0){
						$('input[name="orgCodeBack"]').each(function(){
							if($(this).attr("checked")=="checked"){
								$(this).removeAttr("checked");
							}
						}); 
					}
					$.ajax({
						url:'selbase!selOrgStrapVcltwo.action',
						data:{"Codeimg":"removeCode","nameImg":"removeName"},
						dataType:'text',
						type:'post',
						error:function(){		
						}
					});
					$("input[name=orgCode]").val("");
					$("#nowOrgCode").remove();
				});
			}
			});
	
	}
	}
}
	if(content.length == 0){
		return;
	}
	var div$ = $("<div>").attr("id","nowOrgCode")
	 		.attr("title",content)
	 		.css("position","absolute")
	 		.css("display","none")
	 		.html(zoomContent);
	var img$ = $("<img>").attr("id","closeImg")
						.attr("src","images/custom/close.gif")
						 .attr("title","关闭");
	if($("#inputImg").length==0){
	var input$ = $("<input>").attr("id","inputImg")
							.css("display","none")
							.val(zoomContent);
	}else{
		input$=$("#inputImg");
		$("#inputImg").val(zoomContent);
	}
	/*$.ajax({
		url:'selbase!selOrgStrapVcltwo.action',
		data:{"zoomContent":zoomContent},
		dataType:'text',
		type:'post',
		error:function(){		
		},
		success:function(data){
			
		}
		});*/
	
	img$.click(function(){
		$("#orgCode0").val("");
		$("#zoomContent0").val("");
		$.ajax({
			url:'selbase!selOrgStrapVcltwo.action',
			data:{"Codeimg":"removeCode","nameImg":"removeName"},
			dataType:'text',
			type:'post',
			error:function(){		
			}
			});
		$("input[name=orgCode]").val("");
		$("input[name='orgCodeBack']").attr("checked",false);
		$("#nowOrgCode").remove();
	});
	input$.appendTo(div$)
	img$.appendTo(div$);
	div$.appendTo($("body"));
	var width = div$.width();
	var searchtextleft =  searchtext.offset().left-18;
	var searchtexttop = searchtext.offset().top;
	var left = searchtextleft-width;
	var top = searchtexttop;
	div$.css("left",left)
		.css("top",top)
		.css("display","block")
		.css("width",width+10)
		.addClass("orgCode");
	$("input[name=orgCode]").val(orgCodeContent);
	orgstrapvclScrollTop = $(".orgstrapvcl").scrollTop();
//	$(".orgstrapvcl").hide();
	//赋值系统变量，用于回显
	window.parent.nowOrgCode = orgName;
}

function selOrgCode2(id,code,name){
	callBack_SelOrg(id,code,name);
	orgstrapvclScrollTop = $(".orgstrapvcl").scrollTop();
	$(".orgstrapvcl").hide();
}

//
function sendTop(up_OrganizationCode,TopObject){
	var cat = eval("down_"+up_OrganizationCode);
	if(cat.style.display=="none"){

		cat.style.display="block";
		if(TopObject=="true"){
			document.getElementById("img_lx_"+up_OrganizationCode).src="./images/org/dashminus.gif";
			}
		else{document.getElementById("img_lx_"+up_OrganizationCode).src="./images/org/lminus.gif";
		}
	}else{
		cat.style.display="none";
		if(TopObject=="true"){
		document.getElementById("img_lx_"+up_OrganizationCode).src="./images/org/dashplus.gif";
		}else{
		document.getElementById("img_lx_"+up_OrganizationCode).src="./images/org/lplus.gif";
		}
		
	}
	
}